def prime(a):
    for i in range(2,a):
        if a%i==0:
            return 0
    return 1
a = int(input('Введите число '))
if a<1000 and a>=10000:
    print(0)
else:
    if prime(a)==1:
        M=a
    else:
        M=0
        while a!=0:
            x=a%10
            y=a%100
            z=a%1000
            if prime(x): M = max(M, x)
            if prime(y): M = max(M, y)
            if prime(z): M = max(M, z)
            a//=10
print(M)
